//
//  MBProgressHUD+LJ.m
//  lntuApp
//
//  Created by 李杰 on 14-9-18.
//  Copyright (c) 2014年 PUPBOSS. All rights reserved.
//

#import "MBProgressHUD+LJ.h"

#define kSKMDefaultDuration 0.9
@implementation MBProgressHUD (LJ)

#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].windows.firstObject ;
    
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.detailsLabelText = text;
    
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    
    hud.detailsLabelFont = [UIFont systemFontOfSize:16.0];
    
    // 0.9秒之后再消失
    [hud hide:YES afterDelay:kSKMDefaultDuration];
}


+(void)showText:(NSString *)text
{
    [self showText:text withDuration:kSKMDefaultDuration];
}

+ (void)showText:(NSString *)text withDuration:(NSTimeInterval)duration
{
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].windows.firstObject animated:YES];
    hud.detailsLabelText = text;
    
    // 再设置模式
    hud.mode = MBProgressHUDModeText;
    
    hud.color = [UIColor blackColor];
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    hud.detailsLabelFont = [UIFont systemFontOfSize:16.0];
    
    // 持续duration秒之后再消失
    [hud hide:YES afterDelay:duration];
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view {
    
    [self show:error icon:@"error.png" view:view];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view {
    
    [self show:success icon:@"success.png" view:view];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    
    if (view == nil) view = [[UIApplication sharedApplication].windows firstObject];
    
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.detailsLabelText = message;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // YES代表需要蒙版效果
    hud.dimBackground = NO;
    
    hud.color = [UIColor blackColor];
    
    hud.detailsLabelFont = [UIFont systemFontOfSize:16.0];
    return hud;
}

+ (void)showSuccess:(NSString *)success
{
    [self showSuccess:success toView:nil];
}

+ (void)showError:(NSString *)error
{
    [self showError:error toView:nil];
}

+ (MBProgressHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}

+ (void)hideHUDForView:(UIView *)view
{
    [self hideAllHUDsForView:view animated:YES];
}

+ (void)hideHUD
{
    UIView *view = [[UIApplication sharedApplication].windows firstObject];
    [self hideHUDForView:view];
}
@end
